<%--
  Created by IntelliJ IDEA.
  User: 姜姒
  Date: 2022/5/13
  Time: 9:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>添加楼栋</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/ajaxForm.js"></script>
</head>
<script>
    layui.use(['form', 'laydate', 'layer'], function () {
        var form = layui.form, laydate = layui.laydate, layer = layui.layer;


        form.verify({

            newmobile: function(value){
                if(value.length != 3){
                    return '长度只能是两位数';
                }
            },
            v_pass:[/^[\s]{1,3}$/,'长度不能超过三位数'],
            numberRequiredFalse:[/(^$)|^\d+$/,'只能填写数字'],//非必填项，填了就会进行验证
            username: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '楼栋不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '首尾不能出现下划线\'_\'';
                }

            }
        });

        $(function () {
            form.val('formsbt',${sf});//将对象赋给表单，自动赋值
            form.render();
        });

        form.on('submit(formBtn)',function(data){
            var formData = new FormData($("#formsbt")[0]);
            $.ajax({
                url:'${pageContext.request.contextPath}/houqing/loudongupd',
                type : 'POST',
                data : formData,
                cache: false,
                async: false,
                processData : false,  //必须false才会避开jQuery对 formdata 的默认处理
                contentType : false,  //必须false才会自动加上正确的Content-Type
                success:function(data){
                    layer.msg('修改成功！',{icon:6,offset:"auto",time:2000});//提示框
                    setTimeout(function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);//关闭弹出层
                        parent.location.reload();//重新加载父页面表格
                    }, 1100);
                }
            })
            return false;
        });



    });
</script>
<body>
<form class="layui-form" id="formsbt" lay-filter="formsbt">


    <div class="layui-form-item">
        <input type="hidden" name="floorId">
        <label class="layui-form-label">楼栋名称:</label>
        <div class="layui-input-inline">
            <input type="text" name="floorName" class="layui-input" placaholder="楼栋名称" lay-verify="required|username|numberRequiredFalse"/>
        </div>

    </div>


    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="formBtn">修改</button>
        </div>
    </div>
</form>
</body>
</html>
